﻿using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using StepsManagerLibrary.Enum;
using StepsManagerLibrary.Events;
using StepsManagerLibrary.Interfaces;

namespace WPF_Example.ViewModel
{
    public class StepViewModel : BaseViewModel
    {
        #region Fields

        private readonly IStepControl _control;

        #endregion

        #region Properties

        private string _movingToTitle;

        public string MovingToTitle
        {
            get { return _movingToTitle; }
            set
            {
                _movingToTitle = value;
                OnPropertyChanged("MovingToTitle");
            }
        }

        #endregion

        #region Commands

        #region MoveFirst

        // Move to the previous step
        private readonly ICommand _moveFirstCommand;
        public ICommand MoveFirstCommand
        {
            get { return _moveFirstCommand; }
        }

        private void MoveFirstAction()
        {
            _control.StartAction(StepActionTypeEnum.MoveFirst, null);
        }

        #endregion

        #region MovePrevious

        // Move to the previous step
        private readonly ICommand _movePreviousCommand;
        public ICommand MovePreviousCommand
        {
            get { return _movePreviousCommand; }
        }

        private void MovePreviousAction()
        {
            _control.StartAction(StepActionTypeEnum.MovePrevious, null);
        }

        #endregion

        #region MoveNext

        // Move to the Next step
        private readonly ICommand _moveNextCommand;
        public ICommand MoveNextCommand
        {
            get { return _moveNextCommand; }
        }

        private void MoveNextAction()
        {
            _control.StartAction(StepActionTypeEnum.MoveNext, null);
        }

        #endregion

        #region MoveLast

        // Move to the last step
        private readonly ICommand _moveLastCommand;
        public ICommand MoveLastCommand
        {
            get { return _moveLastCommand; }
        }

        private void MoveLastAction()
        {
            _control.StartAction(StepActionTypeEnum.MoveLast, null);
        }

        #endregion

        #region MoveTo

        // Move to the previous step
        private readonly ICommand _moveToCommand;
        public ICommand MoveToCommand
        {
            get { return _moveToCommand; }
        }

        private void MoveToAction()
        {
            _control.StartAction(StepActionTypeEnum.MoveTo, new ActionEventArgs(_movingToTitle));
        }

        #endregion

        #endregion

        #region Constructors

        public StepViewModel(IStepControl stepControl)
        {
            _moveFirstCommand = new DelegateCommand(MoveFirstAction);
            _movePreviousCommand = new DelegateCommand(MovePreviousAction);
            _moveLastCommand = new DelegateCommand(MoveLastAction);
            _moveNextCommand = new DelegateCommand(MoveNextAction);
            _moveToCommand = new DelegateCommand(MoveToAction);

            _control = stepControl;

            _movingToTitle = "Step 3";
        }

        #endregion
    }
}
